<?php
class NdungDoituongsController extends AppController {

	var $name = 'NdungDoituongs';
	var $helpers = array('Html', 'Form');

	function index() {
		$this->NdungDoituong->recursive = 0;
		$this->set('ndungDoituongs', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid NdungDoituong.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('ndungDoituong', $this->NdungDoituong->read(null, $id));
	}




/*phuong thuc add cu
	function add() {
		if (!empty($this->data)) {
			$this->NdungDoituong->create();
			if ($this->NdungDoituong->save($this->data)) {
				$this->Session->setFlash(__('The NdungDoituong has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The NdungDoituong could not be saved. Please, try again.', true));
			}
		}
		$ndDts = $this->NdungDoituong->NdDt->find('list');
		$doituongs = $this->NdungDoituong->Doituong->find('list');
		$this->set(compact('ndDts', 'doituongs'));
	}
*/
	function add() {
		if (!empty($this->data)) {
			$this->NdungDoituong->create();
			if ($this->NdungDoituong->save($this->data)) {
				$this->Session->setFlash(__('The NdungDoituong has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The NdungDoituong could not be saved. Please, try again.', true));
			}
		}
		$ndDts = $this->NdungDoituong->NdDt->find('list');
		$doituongs = $this->NdungDoituong->Doituong->find('list');
		$this->set(compact('ndDts', 'doituongs'));
	}
/*MAU
	function add() {
		if (!empty($this->data)) {
			$this->PdtDoituong->create();
			$pdt_id = $this->data['PdtDoituong']['phieu_dt_id'];
			foreach($this->data['PdtDoituong']['doituong_id'] as $key=>$value){
				$record['PhieuDt']['id'] = $pdt_id;
				$record['Doituong']['id'] = $value;
				if (!$this->PdtDoituong->saveAll($record)) {
					$this->Session->setFlash(__('The PdtDoituong could not be saved. Please, try again.', true));
					$this->redirect(array('action'=>'index'));
				}
			}
			$this->Session->setFlash(__('The PdtDoituong has been saved', true));
			$this->redirect(array('action'=>'index'));
			
		}
		$phieuDts = $this->PdtDoituong->PhieuDt->find('list');
		$doituongs = $this->PdtDoituong->Doituong->find('list');
		$this->set(compact('phieuDts', 'doituongs'));
	}
	*/
	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid NdungDoituong', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->NdungDoituong->save($this->data)) {
				$this->Session->setFlash(__('The NdungDoituong has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The NdungDoituong could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->NdungDoituong->read(null, $id);
		}
		$ndDts = $this->NdungDoituong->NdDt->find('list');
		$doituongs = $this->NdungDoituong->Doituong->find('list');
		$this->set(compact('ndDts','doituongs'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for NdungDoituong', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->NdungDoituong->del($id)) {
			$this->Session->setFlash(__('NdungDoituong deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}


	function admin_index() {
		$this->NdungDoituong->recursive = 0;
		$this->set('ndungDoituongs', $this->paginate());
	}

	function admin_view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid NdungDoituong.', true));
			$this->redirect(array('action'=>'index'));
		}
		$this->set('ndungDoituong', $this->NdungDoituong->read(null, $id));
	}

	function admin_add() {
		if (!empty($this->data)) {
			$this->NdungDoituong->create();
			if ($this->NdungDoituong->save($this->data)) {
				$this->Session->setFlash(__('The NdungDoituong has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The NdungDoituong could not be saved. Please, try again.', true));
			}
		}
		$ndDts = $this->NdungDoituong->NdDt->find('list');
		$doituongs = $this->NdungDoituong->Doituong->find('list');
		$this->set(compact('ndDts', 'doituongs'));
	}

	function admin_edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid NdungDoituong', true));
			$this->redirect(array('action'=>'index'));
		}
		if (!empty($this->data)) {
			if ($this->NdungDoituong->save($this->data)) {
				$this->Session->setFlash(__('The NdungDoituong has been saved', true));
				$this->redirect(array('action'=>'index'));
			} else {
				$this->Session->setFlash(__('The NdungDoituong could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->NdungDoituong->read(null, $id);
		}
		$ndDts = $this->NdungDoituong->NdDt->find('list');
		$doituongs = $this->NdungDoituong->Doituong->find('list');
		$this->set(compact('ndDts','doituongs'));
	}

	function admin_delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for NdungDoituong', true));
			$this->redirect(array('action'=>'index'));
		}
		if ($this->NdungDoituong->del($id)) {
			$this->Session->setFlash(__('NdungDoituong deleted', true));
			$this->redirect(array('action'=>'index'));
		}
	}

}
?>